from machine import UART
import sensor, image, time

sensor.reset()                          #OpenArt感光元件初始化
sensor.set_pixformat(sensor.RGB565)     #设置图片像素模式，彩色，每个像素16bit
sensor.set_framesize(sensor.QQVGA)      #QQVGA: 160x120
sensor.set_brightness(2000)             #设置亮度
sensor.skip_frames(time = 20)           #跳过不稳定的帧
sensor.set_auto_gain(False)             #颜色模式下关闭
sensor.set_auto_whitebal(False)
clock = time.clock()


#采集数据集图片
save_img_num = 0
while True:
    img = sensor.snapshot()
    for r in img.find_rects(threshold = 50000):
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        img1 = img.copy(r.rect())
        save_img_num += 1
        image_pat = "/num"+str(save_img_num)+".jpg"
        img1.save(image_pat,quality=100)


